Change in openvpn[master]: Silence unhelpful compiler truncation warning with bigger buffer
A message that is not in the archive (sent off-list or not yet received): gerrit.1760441635000.I54b11a5540fb236580a3b80c6d1e8678b24bd852@...2715...
Attention is currently required from: flichtenheld.
Hello flichtenheld,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/1272?usp=email
to review the following change.
Change subject: Silence unhelpful compiler truncation warning with bigger buffer
......................................................................
Silence unhelpful compiler truncation warning with bigger buffer
On the more recent mingw compilers (homebrew mingw 13.0.0, GCC 15.2.0) the compiler complains about a potential truncation in these two places.
src/openvpn/tun.c:3806:57:
error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 178 [-Werror=format-truncation=]
This not very helpful but just increasing the buffer sizes makes the warning go away.
---
M src/openvpn/tun.c
1 file changed, 2 insertions(+), 2 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/72/1272/1
src/openvpn/tun.c +2 -2
@@ -3784,7 +3784,7 @@while (true) {char enum_name[256 ]; -char unit_string[256 ]; +char unit_string[512 ];HKEY unit_key;char component_id_string[] ="ComponentId" ;char component_id[256 ];
@@ -3895,7 +3895,7 @@while (true) {char enum_name[256 ]; -char connection_string[256 ]; +char connection_string[512 ];HKEY connection_key;WCHAR name_data[256 ];DWORD name_type;
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1272?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I54b11a5540fb236580a3b80c6d1e8678b24bd852
Gerrit-Change-Number: 1272
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
[Openvpn-devel] [S] Change in openvpn[master]: Silence compiler truncation warning by checking snprintf return value
In reply to a message not in the archiveAttention is currently required from: flichtenheld.
Hello flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1272?usp=email
to look at the new patch set (#2).
Change subject: Silence compiler truncation warning by checking snprintf return value
......................................................................
Silence compiler truncation warning by checking snprintf return value
On the more recent mingw compilers (homebrew mingw 13.0.0, GCC 15.2.0) the compiler complains about a potential truncation in these two places.
src/openvpn/tun.c:3806:57:
error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 178 [-Werror=format-truncation=]
This not very helpful but checking the snprintf return value will make the compiler not warn about this.
---
M src/openvpn/tun.c
1 file changed, 14 insertions(+), 3 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/72/1272/2
src/openvpn/tun.c +14 -3
@@ -3803,7 +3803,12 @@msg (M_FATAL ,"Error enumerating registry subkeys of key: %s" ,ADAPTER_KEY ); } -snprintf (unit_string,sizeof (unit_string),"%s\\%s" ,ADAPTER_KEY , enum_name); +int ret =snprintf (unit_string,sizeof (unit_string),"%s\\%s" ,ADAPTER_KEY , enum_name); + +if (ret <0 || ret >=sizeof (unit_string)) + { +msg (M_FATAL ,"Error constructing unit string for %s" , enum_name); + } status =RegOpenKeyEx (HKEY_LOCAL_MACHINE , unit_string,0 ,KEY_READ , &unit_key);
@@ -3912,8 +3917,14 @@msg (M_FATAL ,"Error enumerating registry subkeys of key: %s" ,NETWORK_CONNECTIONS_KEY ); } -snprintf (connection_string,sizeof (connection_string),"%s\\%s\\Connection" , -NETWORK_CONNECTIONS_KEY , enum_name); +int ret =snprintf (connection_string,sizeof (connection_string),"%s\\%s\\Connection" , +NETWORK_CONNECTIONS_KEY , enum_name); + +if (ret <0 || ret >=sizeof (connection_string)) + { +msg (M_FATAL ,"Error constructing connection string for %s" , enum_name); + } + status =RegOpenKeyEx (HKEY_LOCAL_MACHINE , connection_string,0 ,KEY_READ , &connection_key);
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1272?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I54b11a5540fb236580a3b80c6d1e8678b24bd852
Gerrit-Change-Number: 1272
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
[Openvpn-devel] [S] Change in openvpn[master]: Silence compiler truncation warning by checking snprintf return value
In reply to a message not in the archiveAttention is currently required from: plaisthos.
flichtenheld has posted comments on this change by plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/1272?usp=email )
Change subject: Silence compiler truncation warning by checking snprintf return value
......................................................................
Patch Set 3: Code-Review-1
(3 comments)
Patchset:
PS3:
Hi. Had ignored this for a while mostly because mingw 13.0.0 isn't present in our buildbot fleet, yet. But tested it now and it indeed resolves the issue. But see comments about error handling.
File src/openvpn/tun.c:
http://gerrit.openvpn.net/c/openvpn/+/1272/comment/8ce84b65_d5cb1a44?usp=email :
PS3, Line 3565: M_FATAL
I think M_FATAL is too drastic here. A continue would also be okay, like we do for errors on RegOpenKeyEx a few lines below.
http://gerrit.openvpn.net/c/openvpn/+/1272/comment/3f5b513f_6359ba5c?usp=email :
PS3, Line 3680: msg(M_FATAL, "Error constructing connection string for %s", enum_name);
I think M_FATAL is too drastic here. A continue would also be okay, like we do for errors on RegOpenKeyEx a few lines below.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1272?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I54b11a5540fb236580a3b80c6d1e8678b24bd852
Gerrit-Change-Number: 1272
Gerrit-PatchSet: 3
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Comment-Date: Wed, 14 Jan 2026 16:01:00 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
[Openvpn-devel] [S] Change in openvpn[master]: Silence compiler truncation warning by checking snprintf return value
In reply to a message not in the archiveAttention is currently required from: flichtenheld, plaisthos.
Hello flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1272?usp=email
to look at the new patch set (#4).
The following approvals got outdated and were removed:
Code-Review-1 by flichtenheld
Change subject: Silence compiler truncation warning by checking snprintf return value
......................................................................
Silence compiler truncation warning by checking snprintf return value
On the more recent mingw compilers (homebrew mingw 13.0.0, GCC 15.2.0) the compiler complains about a potential truncation in these two places.
src/openvpn/tun.c:3806:57:
error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 178 [-Werror=format-truncation=]
This not very helpful but checking the snprintf return value will make the compiler not warn about this.
---
M src/openvpn/tun.c
1 file changed, 16 insertions(+), 3 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/72/1272/4
src/openvpn/tun.c +16 -3
@@ -3558,7 +3558,13 @@msg (M_FATAL ,"Error enumerating registry subkeys of key: %s" ,ADAPTER_KEY ); } -snprintf (unit_string,sizeof (unit_string),"%s\\%s" ,ADAPTER_KEY , enum_name); +int ret =snprintf (unit_string,sizeof (unit_string),"%s\\%s" ,ADAPTER_KEY , enum_name); + +if (ret <0 || ret >=sizeof (unit_string)) + { +msg (M_WARN ,"Error constructing unit string for %s" , enum_name); +continue ; + } status =RegOpenKeyEx (HKEY_LOCAL_MACHINE , unit_string,0 ,KEY_READ , &unit_key);
@@ -3667,8 +3673,15 @@msg (M_FATAL ,"Error enumerating registry subkeys of key: %s" ,NETWORK_CONNECTIONS_KEY ); } -snprintf (connection_string,sizeof (connection_string),"%s\\%s\\Connection" , -NETWORK_CONNECTIONS_KEY , enum_name); +int ret =snprintf (connection_string,sizeof (connection_string),"%s\\%s\\Connection" , +NETWORK_CONNECTIONS_KEY , enum_name); + +if (ret <0 || ret >=sizeof (connection_string)) + { +msg (M_WARN ,"Error constructing connection string for %s" , enum_name); +continue ; + } + status =RegOpenKeyEx (HKEY_LOCAL_MACHINE , connection_string,0 ,KEY_READ , &connection_key);
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1272?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I54b11a5540fb236580a3b80c6d1e8678b24bd852
Gerrit-Change-Number: 1272
Gerrit-PatchSet: 4
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
[Openvpn-devel] [S] Change in openvpn[master]: Silence compiler truncation warning by checking snprintf return value
In reply to a message not in the archiveAttention is currently required from: flichtenheld.
plaisthos has posted comments on this change by plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/1272?usp=email )
Change subject: Silence compiler truncation warning by checking snprintf return value
......................................................................
Patch Set 4:
(2 comments)
File src/openvpn/tun.c:
http://gerrit.openvpn.net/c/openvpn/+/1272/comment/82bebc2d_983e8fec?usp=email :
PS3, Line 3565: M_FATAL
Quoted 1 line
I think
M_FATALis too drastic here. […]
changed to M_WARN and continue
http://gerrit.openvpn.net/c/openvpn/+/1272/comment/79e63da6_66dea17c?usp=email :
PS3, Line 3680: msg(M_FATAL, "Error constructing connection string for %s", enum_name);
Quoted 1 line
I think
M_FATALis too drastic here. […]
changed to M_WARN and continue
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1272?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I54b11a5540fb236580a3b80c6d1e8678b24bd852
Gerrit-Change-Number: 1272
Gerrit-PatchSet: 4
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 20 Jan 2026 18:18:07 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
[Openvpn-devel] [S] Change in openvpn[master]: Silence compiler truncation warning by checking snprintf return value
In reply to a message not in the archiveAttention is currently required from: plaisthos.
flichtenheld has posted comments on this change by plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/1272?usp=email )
Change subject: Silence compiler truncation warning by checking snprintf return value
......................................................................
Patch Set 4: Code-Review+2
(2 comments)
File src/openvpn/tun.c:
http://gerrit.openvpn.net/c/openvpn/+/1272/comment/d68ea71a_95163523?usp=email :
PS3, Line 3565: M_FATAL
Quoted 1 line
changed to
M_WARNand continue
Done
http://gerrit.openvpn.net/c/openvpn/+/1272/comment/de6a3602_4b832d38?usp=email :
PS3, Line 3680: msg(M_FATAL, "Error constructing connection string for %s", enum_name);
Quoted 1 line
changed to
M_WARNand continue
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1272?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I54b11a5540fb236580a3b80c6d1e8678b24bd852
Gerrit-Change-Number: 1272
Gerrit-PatchSet: 4
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Comment-Date: Wed, 21 Jan 2026 11:54:16 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: plaisthos <[email protected]...>
Comment-In-Reply-To: flichtenheld <[email protected]...>
PATCH v4 1/1 Silence compiler truncation warning by checking snprintf return value
In reply to a message not in the archiveFrom: Arne Schwabe <[email protected]...>
On the more recent mingw compilers (homebrew mingw 13.0.0, GCC 15.2.0) the compiler complains about a potential truncation in these two places.
src/openvpn/tun.c:3806:57:
error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 178 [-Werror=format-truncation=]
This not very helpful but checking the snprintf return value will make the compiler not warn about this.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1272
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1272
This mail reflects revision 4 of this Change.
Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <[email protected]...>
src/openvpn/tun.c +16 -3
@@ -3558,7 +3558,13 @@msg (M_FATAL ,"Error enumerating registry subkeys of key: %s" ,ADAPTER_KEY ); } -snprintf (unit_string,sizeof (unit_string),"%s\\%s" ,ADAPTER_KEY , enum_name); +int ret =snprintf (unit_string,sizeof (unit_string),"%s\\%s" ,ADAPTER_KEY , enum_name); + +if (ret <0 || ret >=sizeof (unit_string)) + { +msg (M_WARN ,"Error constructing unit string for %s" , enum_name); +continue ; + } status =RegOpenKeyEx (HKEY_LOCAL_MACHINE , unit_string,0 ,KEY_READ , &unit_key);
@@ -3667,8 +3673,15 @@msg (M_FATAL ,"Error enumerating registry subkeys of key: %s" ,NETWORK_CONNECTIONS_KEY ); } -snprintf (connection_string,sizeof (connection_string),"%s\\%s\\Connection" , -NETWORK_CONNECTIONS_KEY , enum_name); +int ret =snprintf (connection_string,sizeof (connection_string),"%s\\%s\\Connection" , +NETWORK_CONNECTIONS_KEY , enum_name); + +if (ret <0 || ret >=sizeof (connection_string)) + { +msg (M_WARN ,"Error constructing connection string for %s" , enum_name); +continue ; + } + status =RegOpenKeyEx (HKEY_LOCAL_MACHINE , connection_string,0 ,KEY_READ , &connection_key);
[Openvpn-devel] [PATCH applied] Re: Silence compiler truncation warning by checking snprintf return value
Compilers... but yeah, the change won't do harm, and might catch something unexpected with a proper error message. Doesn't change the actual code flow, so not tested beyond "is the compiler fine with it".
Your patch has been applied to the master branch.
commit 1fe958183fa5877d9e00cbfbe0d29477adff7187
Author: Arne Schwabe Date: Wed Jan 21 13:18:30 2026 +0100
Silence compiler truncation warning by checking snprintf return value
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Frank Lichtenheld <[email protected]...>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1272
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg35367.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [S] Change in openvpn[master]: Silence compiler truncation warning by checking snprintf return value
In reply to a message not in the archivecron2 has uploaded a new patch set (#5) to the change originally created by plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/1272?usp=email )
The following approvals got outdated and were removed:
Code-Review+2 by flichtenheld
Change subject: Silence compiler truncation warning by checking snprintf return value
......................................................................
Silence compiler truncation warning by checking snprintf return value
On the more recent mingw compilers (homebrew mingw 13.0.0, GCC 15.2.0) the compiler complains about a potential truncation in these two places.
src/openvpn/tun.c:3806:57:
error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 178 [-Werror=format-truncation=]
This not very helpful but checking the snprintf return value will make the compiler not warn about this.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1272
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg35367.html
---
M src/openvpn/tun.c
1 file changed, 16 insertions(+), 3 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/72/1272/5
src/openvpn/tun.c +16 -3
@@ -3558,7 +3558,13 @@msg (M_FATAL ,"Error enumerating registry subkeys of key: %s" ,ADAPTER_KEY ); } -snprintf (unit_string,sizeof (unit_string),"%s\\%s" ,ADAPTER_KEY , enum_name); +int ret =snprintf (unit_string,sizeof (unit_string),"%s\\%s" ,ADAPTER_KEY , enum_name); + +if (ret <0 || ret >=sizeof (unit_string)) + { +msg (M_WARN ,"Error constructing unit string for %s" , enum_name); +continue ; + } status =RegOpenKeyEx (HKEY_LOCAL_MACHINE , unit_string,0 ,KEY_READ , &unit_key);
@@ -3667,8 +3673,15 @@msg (M_FATAL ,"Error enumerating registry subkeys of key: %s" ,NETWORK_CONNECTIONS_KEY ); } -snprintf (connection_string,sizeof (connection_string),"%s\\%s\\Connection" , -NETWORK_CONNECTIONS_KEY , enum_name); +int ret =snprintf (connection_string,sizeof (connection_string),"%s\\%s\\Connection" , +NETWORK_CONNECTIONS_KEY , enum_name); + +if (ret <0 || ret >=sizeof (connection_string)) + { +msg (M_WARN ,"Error constructing connection string for %s" , enum_name); +continue ; + } + status =RegOpenKeyEx (HKEY_LOCAL_MACHINE , connection_string,0 ,KEY_READ , &connection_key);
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1272?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I54b11a5540fb236580a3b80c6d1e8678b24bd852
Gerrit-Change-Number: 1272
Gerrit-PatchSet: 5
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
[Openvpn-devel] [S] Change in openvpn[master]: Silence compiler truncation warning by checking snprintf return value
In reply to a message not in the archivecron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1272?usp=email )
Change subject: Silence compiler truncation warning by checking snprintf return value
......................................................................
Silence compiler truncation warning by checking snprintf return value
On the more recent mingw compilers (homebrew mingw 13.0.0, GCC 15.2.0) the compiler complains about a potential truncation in these two places.
src/openvpn/tun.c:3806:57:
error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 178 [-Werror=format-truncation=]
This not very helpful but checking the snprintf return value will make the compiler not warn about this.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1272
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg35367.html
---
M src/openvpn/tun.c
1 file changed, 16 insertions(+), 3 deletions(-)
src/openvpn/tun.c +16 -3
@@ -3558,7 +3558,13 @@msg (M_FATAL ,"Error enumerating registry subkeys of key: %s" ,ADAPTER_KEY ); } -snprintf (unit_string,sizeof (unit_string),"%s\\%s" ,ADAPTER_KEY , enum_name); +int ret =snprintf (unit_string,sizeof (unit_string),"%s\\%s" ,ADAPTER_KEY , enum_name); + +if (ret <0 || ret >=sizeof (unit_string)) + { +msg (M_WARN ,"Error constructing unit string for %s" , enum_name); +continue ; + } status =RegOpenKeyEx (HKEY_LOCAL_MACHINE , unit_string,0 ,KEY_READ , &unit_key);
@@ -3667,8 +3673,15 @@msg (M_FATAL ,"Error enumerating registry subkeys of key: %s" ,NETWORK_CONNECTIONS_KEY ); } -snprintf (connection_string,sizeof (connection_string),"%s\\%s\\Connection" , -NETWORK_CONNECTIONS_KEY , enum_name); +int ret =snprintf (connection_string,sizeof (connection_string),"%s\\%s\\Connection" , +NETWORK_CONNECTIONS_KEY , enum_name); + +if (ret <0 || ret >=sizeof (connection_string)) + { +msg (M_WARN ,"Error constructing connection string for %s" , enum_name); +continue ; + } + status =RegOpenKeyEx (HKEY_LOCAL_MACHINE , connection_string,0 ,KEY_READ , &connection_key);
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1272?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I54b11a5540fb236580a3b80c6d1e8678b24bd852
Gerrit-Change-Number: 1272
Gerrit-PatchSet: 5
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>